package com.douqu.game.core.config.card;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.CommonLvUp;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.entity.db.CardDB;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by bean on 2017/7/21.
 */
public class CardLvConfig extends GameObject {


    public CommonData [] exp;
    public CommonData [] totalExp;
    /**返还的道具，资源，装备*/
    public GoodsData[] restitution;

    /**药水最大使用数量**/
    public Map<Integer, Integer> useLiquidMaxCount;


    public int getTotalExp(int quality){

        for (CommonData commonData :totalExp){
            if(quality == commonData.id)
                return commonData.value;
        }
        return 0;
    }

    @Override
    public boolean check() {
        if(restitution == null)
        {
            LogUtils.error("CardLv check restitution is null -> id:" + id + " name:" + name);
            return false;
        }

        return true;
    }

    @Override
    public boolean setVariable(String key, String value)
    {

        if("exp".equals(key)){
            exp = LoadUtils.loadCommonDataToArray(key, value);
//            return LoadUtils.checkCommonData(exp, this.getClass(), key, DataFactory.ASSET_KEY, id);
            return true;
        }
        else if("totalExp".equals(key)){
            totalExp = LoadUtils.loadCommonDataToArray(key,value);
//            return LoadUtils.checkCommonData(exp, this.getClass(), key, DataFactory.ASSET_KEY, id);
            return true;
        }
        if("restitution".equals(key))
        {
            restitution = LoadUtils.loadGoodDataToArray(key, value);
            GoodsData[] checkData = new GoodsData[restitution.length];
            for(int i = 0; i < restitution.length; i ++){
                checkData[i] = new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE,
                        restitution[i].id, restitution[i].value);
            }
            return LoadUtils.checkGoods(checkData, this.getClass(), key, id);
        }else if("useLiquidMaxCount".equals(key)){
            useLiquidMaxCount = new ConcurrentHashMap<>();
            GoodsData[] datas = LoadUtils.loadGoodDataToArray(key, value);
            for(GoodsData data : datas){
                useLiquidMaxCount.put(data.type, data.id);
            }
            return true;
        }else{
            return super.setVariable(key, value);
        }
    }


}
